package com.speed_run.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.speed_run.service.IAdminService;
import com.speed_run.utils.ResponseEntity;

/**
 * 管理端接口集合
 * @author wafer
 *
 */
@RestController
@RequestMapping("/v1/api/admin")
public class AdminController {

	//登录接口
	@Autowired
	private IAdminService adminService;
	
	//新建圈子和编辑圈子接口
	@PostMapping("/circle")
	public ResponseEntity addCircle(@RequestParam(value = "pic",required = false) MultipartFile pic,Integer id,String name, String introduce) throws Exception{
		return adminService.updateCirlce(pic, id, name, introduce);
	}
	
	/**
	 * 获取圈子表格数据
	 * @param pageNum
	 * @return
	 */
	@GetMapping("/circle/table")
	public ResponseEntity getCircleTable(Integer pageNum) {
		return adminService.getCircleTable(pageNum); 
	}
	
	
	
	/**
	 * 隐藏圈子
	 * @return
	 */
	@PostMapping("/circle/hide")
	public ResponseEntity hideCircle() {
		return null;
	}
	
	/**
	 * 获取momentbyid
	 * @param circleId
	 * @return
	 */
	@GetMapping("/circle")
	public ResponseEntity getMomentByCircleId(Integer circleId, Integer index){
		return null;
	}
	
	@GetMapping("/focus/imgs")
	public ResponseEntity getFocusImg(){
		return adminService.getFocusImgs();
	}
	
	@DeleteMapping("/focus/img")
	public ResponseEntity delFocusImg(Integer id){
		return adminService.delImg(id);
	}
	
	@PostMapping("/focus/img")
	public ResponseEntity updateFocusImg(@RequestParam(value = "img",required = false) MultipartFile img, Integer id){
		if(id == null) {
			return adminService.insertImg(img);
		}
		return adminService.updateImg(id, img);
	}
	
	@PostMapping("/strategy")
	public  ResponseEntity  updateStrategy(@RequestParam(value="img",required= false) MultipartFile img, String name, Integer id) {
		return adminService.updateStrategy(name, id, img);
	}
	
	@GetMapping("/strategies")
	public ResponseEntity getAllStrategy() {
		return adminService.getALLStrategy();
	}
	
	
	@GetMapping("/articles")
	public ResponseEntity getArticleById(Integer id) {
		return adminService.getArticleById(id);
	}
	
	
	@PostMapping("/article")
	public ResponseEntity updateArticle(Integer id, @RequestParam(value="img",required= false) MultipartFile img, String name) {
		return adminService.updateArticle(name, id, img);
	}
	
}
